//http://acm.whu.edu.cn/blog/read.php?24#entrymore
#include<iostream>
#include<string>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        string a,b;
        int la,lb,i,j,k;
        cin>>a>>b;
        la=a.size();
        lb=b.size();
        int s[lb];
        int max=0;
        for(i=0;i<la;i++)
        for(j=lb-1;j>=0;j--)
        {
            if(a[i]!=b[j]) s[j]=0;
            else
            {
                if(i==0||j==0) s[j]=1;
                else s[j] =s[j-1]+1;
            }
            if(max<s[j]) max=s[j];
        }
        cout<<max<<endl;
    }
    return 0;
}
